//
// File:	GuiMenuMain.cpp
// Author:	Thomas TISSOT-DUPONT
// E-mail:	<thomas.tissotdupont@free.fr>
// Create:	08/01/2010 00:22:30
// Purpose:	
//

#include <QtGui/QApplication>
#include <QtGui/QMessageBox>
#include "Base.hpp"
#include "GuiMenuMain.hpp"
#include "Trace.hpp"

//------------------------------------------------------------------
// Constructor / Destructor
//------------------------------------------------------------------
GuiMenuMain::GuiMenuMain(QWidget *pParent /* = NULL */)
	:	GuiPanel(pParent)
{
	//Menu
	setObjectName("MenuMain");

	//Create Game
	_menuButtons[ButtonCreateGame] = new GuiPushButton(this);
	_menuButtons[ButtonCreateGame]->setText("Create Game");
	_menuButtons[ButtonCreateGame]->setObjectName("ButtonCreateGame");
	_menuButtons[ButtonCreateGame]->resize(200, 25);
	_menuButtons[ButtonCreateGame]->move(39, 215);

	//Resume Game (instead of ButtonCreateGame)
	_menuButtons[ButtonResumeGame] = new GuiPushButton(this);
	_menuButtons[ButtonResumeGame]->setText("Resume Game");
	_menuButtons[ButtonResumeGame]->setObjectName("ButtonResumeGame");
	_menuButtons[ButtonResumeGame]->resize(200, 25);
	_menuButtons[ButtonResumeGame]->move(39, 215);

	//Join Game
	_menuButtons[ButtonJoinGame] = new GuiPushButton(this);
	_menuButtons[ButtonJoinGame]->setText("Join Game");
	_menuButtons[ButtonJoinGame]->setObjectName("ButtonJoinGame");
	_menuButtons[ButtonJoinGame]->resize(200, 25);
	_menuButtons[ButtonJoinGame]->move(32, 240);

	//Disconnect (instead of ButtonJoinGame)
	_menuButtons[ButtonDisconnect] = new GuiPushButton(this);
	_menuButtons[ButtonDisconnect]->setText("Disconnect");
	_menuButtons[ButtonDisconnect]->setObjectName("ButtonDisconnect");
	_menuButtons[ButtonDisconnect]->resize(200, 25);
	_menuButtons[ButtonDisconnect]->move(32, 240);

	//Options
	_menuButtons[ButtonOptions] = new GuiPushButton(this);
	_menuButtons[ButtonOptions]->setText("Options");
	_menuButtons[ButtonOptions]->setObjectName("ButtonOptions");
	_menuButtons[ButtonOptions]->resize(125, 25);
	_menuButtons[ButtonOptions]->move(35, 265);

	//Quit
	_menuButtons[ButtonQuit] = new GuiPushButton(this);
	_menuButtons[ButtonQuit]->setText("Quit");
	_menuButtons[ButtonQuit]->setObjectName("ButtonQuit");
	_menuButtons[ButtonQuit]->resize(125, 25);
	_menuButtons[ButtonQuit]->move(45, 290);

	//Slots
	QObject::connect(_menuButtons[ButtonCreateGame], SIGNAL(clicked()), this, SLOT(onCreateGameClicked()));
	QObject::connect(_menuButtons[ButtonResumeGame], SIGNAL(clicked()), this, SLOT(onResumeGameClicked()));
	QObject::connect(_menuButtons[ButtonDisconnect], SIGNAL(clicked()), this, SLOT(onDisconnectClicked()));
	QObject::connect(_menuButtons[ButtonJoinGame], SIGNAL(clicked()), this, SLOT(onJoinGameClicked()));
	QObject::connect(_menuButtons[ButtonOptions], SIGNAL(clicked()), this, SLOT(onOptionsClicked()));
	QObject::connect(_menuButtons[ButtonQuit], SIGNAL(clicked()), this, SLOT(onQuitClicked()));
}

GuiMenuMain::~GuiMenuMain()
{
}

//------------------------------------------------------------------
// Events
//------------------------------------------------------------------
void GuiMenuMain::showEvent(QShowEvent *e)
{
	GuiPanel::showEvent(e);
}

//------------------------------------------------------------------
// Update
//------------------------------------------------------------------
void GuiMenuMain::Update()
{
	_menuButtons[ButtonCreateGame]->setVisible(!GlobalVariables::Engine::Get().IsInGame());
	_menuButtons[ButtonJoinGame]->setVisible(!GlobalVariables::Engine::Get().IsInGame());
	_menuButtons[ButtonResumeGame]->setVisible(GlobalVariables::Engine::Get().IsInGame());
	_menuButtons[ButtonDisconnect]->setVisible(GlobalVariables::Engine::Get().IsInGame());
}

//------------------------------------------------------------------
// Slots
//------------------------------------------------------------------
void GuiMenuMain::onCreateGameClicked()
{
	//GlobalVariables::Engine::Get().StartGame();

	GlobalVariables::GuiManager::Get().ShowPanel("menucreategame");
}

void GuiMenuMain::onResumeGameClicked()
{
	GlobalVariables::GuiManager::Get().SetVisible(false);
	GlobalVariables::DisplayManager::Get().SetActive(true);
}

void GuiMenuMain::onDisconnectClicked()
{
	GlobalVariables::Engine::Get().StopGame();
}

void GuiMenuMain::onJoinGameClicked()
{
}

void GuiMenuMain::onOptionsClicked()
{
	GlobalVariables::GuiManager::Get().ShowPanel("menuoptions");
}

void GuiMenuMain::onQuitClicked()
{
	GlobalVariables::Engine::Get().Stop();
}
